<template>

  <div>
    <!-- 查询插件 -->
        <!-- 查询插件 -->
    <div>
      <el-form ref="queryParams" :model="queryParams" :inline="true" label-width="80px" class="loginForm">


        <el-form-item label="合同编号">
          <el-input v-model="queryParams.conno"></el-input>
        </el-form-item>

        <!-- <el-form-item label="合同名称">
          <el-input v-model="queryParams.conname"></el-input>
        </el-form-item> -->

        <el-form-item label="电话号码">
          <el-input v-model="queryParams.conphone"></el-input>
        </el-form-item>

        <el-form-item label="订单状态">
            <el-select
              v-model="queryParams.constate"
              placeholder="请选择"
              clearable
            >
              <el-option label="激活" value="1"></el-option>
              <el-option label="未激活" value="0"></el-option>
            </el-select>
          </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="searchContract">查询</el-button>
          <el-button type="primary" @click="RentContractAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- stu展示插件 -->
    <div>
      <el-table :data="pageBean.beanList" border style="width: 100%">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="conid" label="合同ID"></el-table-column>
        <el-table-column prop="conno" label="合同编号"></el-table-column>
        <el-table-column prop="conname" label="合同名称"></el-table-column>
        <el-table-column prop="contime" label="合同建立时间"></el-table-column>
        <el-table-column prop="conphone" label="合同电话"></el-table-column>
        <el-table-column prop="conway" label="合同来源"></el-table-column>
        <el-table-column prop="constate" label="合同状态">
          
          <!--   active-value="1"
            inactive-value="0"-->
          <template slot-scope="scope">
            <el-switch  
             active-value="1"
            inactive-value="0"
            @change="switchChange(scope.row,scope.row.status)"
             v-model="scope.row.status" active-color="#13ce66" inactive-color="#ff4949" >
            </el-switch>
            
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 分页插件 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageBean.pageIndex"
        :page-sizes="[3, 4, 5, 6,10]"
        :page-size="pageBean.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageBean.totalRecord"
      ></el-pagination>
         </div>


         <!-- 添加故障的模态框 -->
     


    <!-- 模态框插件 -->
    
        <div>
      <el-dialog :title="title" :visible.sync="dialogFormVisible" @close="closeDialog">
        <el-form
          ref="eitParams"
          :model="eitParams"
          :inline="true"
          label-width="80px"

        >
          <el-form-item label="合同编号" prop="conno" label-width="120px">
            <el-input v-model="eitParams.conno"></el-input>
          </el-form-item>
          <el-form-item label="合同名称" prop="conname" label-width="120px">
            <el-input v-model="eitParams.conname"></el-input>
          </el-form-item>
          <!-- <el-form-item label="合同建立时间" prop="contime" label-width="120px">
            <el-input v-model="eitParams.contime"></el-input>
          </el-form-item> -->
          <el-form-item label="合同建立时间" prop="contime" label-width="120px">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="eitParams.contime"
              value-format="yyyy-MM-dd"
              style="width: 150%;"
            ></el-date-picker>
          </el-col>
          </el-form-item>
          <el-form-item label="合同电话" prop=" conphone" label-width="120px">
            <el-input v-model="eitParams.conphone"></el-input>
          </el-form-item>
          <el-form-item label="合同来源" prop=" conway" label-width="120px">
            <el-input v-model="eitParams.conway"></el-input>
          </el-form-item>

           <!-- <el-form-item label="合同建立时间">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="eitParams.contime"
              value-format="yyyy-MM-dd"
              style="width: 150%;"
            ></el-date-picker>
          </el-col>
          </el-form-item> -->

          <el-form-item label="合同状态" label-width="120px">
            <el-select v-model="eitParams.constate" >
              <el-option label="激活" value="1"></el-option>
              <el-option label="未激活" value="0"></el-option>
            </el-select>
          </el-form-item>
      
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="updatestu('eitParams')">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>


<script>
//导入axios
import axios from "axios";

export default {
  data() {
    return {
      // tableData: [],
      pageIndex: 1,
      pageSize: 10,
      pageBean: {
        beanList: [],
        pageIndex: 0,
        pageSize: 0,
        totalRecord: 0,
        totalPage: 0
      },
      queryParams: {
        conid: "",
        conno: "",
        conname:"",
        contime:"",
        conphone: "",
        conway:"",
        constate: ""
      },
      eitParams: {
        conid: "",
        conno: "",
        conname:"",
        contime:"",
        conphone: "",
        conway:"",
        constate: ""
      },
      AddParams: {
        warn_cause: "",
        rentcarid: "",
        warn_time: "",
        process_state:"",
        empid:"",
      },
      dialogFormVisible: false,
      dialogFormVisibletwo:false,
      title: ""
    };
  },
  created() {
    //生命周期方法
     this.getcontractList();
    this.getrole();
    this.getdept();
    // 
  },
  methods: {
   
    updatestu(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (valid) {
            if (this.title == "编辑") {
              this.$axios
                .put("http://localhost:8601/contract/updateContract", this.eitParams)
                .then(resp => {
                  
                  if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                 this.$message("修改成功");
              }
                  
                  this.dialogFormVisible = false;
                   this.getcontractList();
                });
            } else {
              this.$axios
                .put("http://localhost:8601/contract/addContract", this.eitParams)
                .then(resp => {
                   if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                this.$message("添加成功");
              }
                  
                  this.dialogFormVisible = false;
                  this.getcontractList();
                });
            }
          } else {
            console.log("error submit!!");
            return false;
          }

        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handAddWarn(){
       this.dialogFormVisibletwo = true;
        this.AddParams = { ...row };
    },
    handleEdit(index, row) {
      console.log(index, row);
     
      this.dialogFormVisible = true;
      // this.getStudents();
      this.eitParams = { ...row };
      // this.eitParams.did=row.dept.deptname;
      this.title = "编辑";
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios
            .delete("http://localhost:8601/contract/delContract/" + row.conid)
            .then(resp => {
              console.log(resp.data);
              if(resp.data.code==500){
                this.$message("你没有操作权限");
              }else{
                 this.$message("删除成功");
              }
              this.getcontractList();
            });
          // this.$message({
          //   type: "success",
          //   message: "删除成功!"
          // });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    

   getcontractList() {
      this.$axios
        .get("http://localhost:8601/contract/getallContract", {
          params: {
            pageIndex: this.pageIndex,
            pageSize: this.pageSize,
           conid: this.queryParams.conid,
           conno: this.queryParams.conno,
           conname:this.queryParams.conname,
           contime:this.queryParams.contime,
           conphone: this.queryParams.conphone,
           conway:this.queryParams.conway,
           constate:this.queryParams.constate,
          
           
          }
        })
        .then(resp => {
          console.log(resp.data)
          if(resp.data.code==500){
               this.$router.push('/');
          }else{
            this.pageBean = resp.data.data;
          }
          
          
        });
    },
    searchContract() {
      this.getcontractList();
    },
    switchChange(data){
       this.$axios
            .put(`http://localhost:8080/contract/updateContract`,data)
            .then(resp => {
              console.log("修改成功");
              this.getcontractList();
            });
          this.$message({
            type: "success",
            message: "修改成功!"
          });
    },
    RentContractAdd() {
      (this.title = "新增"), (this.dialogFormVisible = true);
    },
    closeDialog() {
      console.log("模态框关闭");
      this.eitParams = {};
      this.$refs["eitParams"].clearValidate();
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getcontractList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageIndex = val;
      this.getcontractList();
    }
  }
};
</script>

<style>
</style>
